package com.xhcl.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xhcl.common.core.domain.Stree;
import com.xhcl.common.core.text.Convert;
import com.xhcl.common.exception.BusinessException;
import com.xhcl.system.domain.TGgDlyhwh;
import com.xhcl.system.mapper.TGgDlyhwhMapper;
import com.xhcl.system.service.ITGgDlyhwhService;

/**
 * 代理银行Service业务层处理
 * 
 * @author xhcl
 * @date 2020-08-24
 */
@Service
public class TGgDlyhwhServiceImpl implements ITGgDlyhwhService 
{
    @Autowired
    private TGgDlyhwhMapper tGgDlyhwhMapper;

    /**
     * 查询代理银行
     * 
     * @param yhbm 代理银行ID
     * @return 代理银行
     */
    @Override
    public TGgDlyhwh selectTGgDlyhwhById(String yhbm)
    {
        return tGgDlyhwhMapper.selectTGgDlyhwhById(yhbm);
    }

    /**
     * 查询代理银行列表
     * 
     * @param tGgDlyhwh 代理银行
     * @return 代理银行
     */
    @Override
    public List<TGgDlyhwh> selectTGgDlyhwhList(TGgDlyhwh tGgDlyhwh)
    {
        return tGgDlyhwhMapper.selectTGgDlyhwhList(tGgDlyhwh);
    }

    /**
     * 新增代理银行
     * 
     * @param tGgDlyhwh 代理银行
     * @return 结果
     */
    @Override
    public int insertTGgDlyhwh(TGgDlyhwh tGgDlyhwh)
    { 
    	
    	TGgDlyhwh yh=tGgDlyhwhMapper.selectTGgDlyhwhById(tGgDlyhwh.getYhbm());
    	if (yh!=null) {
     		throw new BusinessException("银行编码已存在！");
    	}
        return tGgDlyhwhMapper.insertTGgDlyhwh(tGgDlyhwh);
    }

    /**
     * 修改代理银行
     * 
     * @param tGgDlyhwh 代理银行
     * @return 结果
     */
    @Override
    public int updateTGgDlyhwh(TGgDlyhwh tGgDlyhwh)
    {
        return tGgDlyhwhMapper.updateTGgDlyhwh(tGgDlyhwh);
    }

    /**
     * 删除代理银行对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteTGgDlyhwhByIds(String ids)
    {
        return tGgDlyhwhMapper.deleteTGgDlyhwhByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除代理银行信息
     * 
     * @param yhbm 代理银行ID
     * @return 结果
     */
    @Override
    public int deleteTGgDlyhwhById(String yhbm)
    {
        return tGgDlyhwhMapper.deleteTGgDlyhwhById(yhbm);
    }
    
    /**
     * 查询代理银行树列表
     * 
     * @return 所有代理银行信息
     */
    @Override
    public List<Stree> selectTGgDlyhwhTree()
    {
        List<TGgDlyhwh> tGgDlyhwhList = tGgDlyhwhMapper.selectTGgDlyhwhList(new TGgDlyhwh());
        List<Stree> ztrees = new ArrayList<Stree>();
        Stree ztree = new Stree();
        ztree.setId("");
        ztree.setpId("");
        ztree.setName("全部");
        ztree.setTitle("全部");
        ztrees.add(ztree);
        for (TGgDlyhwh tGgDlyhwh : tGgDlyhwhList)
        {
        	Stree ztree1 = new Stree();
        	ztree1.setId(tGgDlyhwh.getYhbm());
        	ztree1.setpId("");
        	ztree1.setName(tGgDlyhwh.getYhbm()+"-"+tGgDlyhwh.getYhmc());
        	ztree1.setTitle(tGgDlyhwh.getYhmc()+"-"+tGgDlyhwh.getSkrzh()+"-"+tGgDlyhwh.getSkrmc());
        	ztrees.add(ztree1);
        }
        return ztrees;
    }
}
